package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.MachineryInfoEntity;
import io.renren.modules.generator.service.MachineryInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 设备信息
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-10-06 01:11:04
 */
@RestController
@RequestMapping("machineryinfo")
public class MachineryInfoController {
	@Autowired
	private MachineryInfoService machineryInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("machineryinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<MachineryInfoEntity> machineryInfoList = machineryInfoService.queryList(query);
		int total = machineryInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(machineryInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("machineryinfo:info")
	public R info(@PathVariable("id") Integer id){
		MachineryInfoEntity machineryInfo = machineryInfoService.queryObject(id);
		
		return R.ok().put("machineryInfo", machineryInfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("machineryinfo:save")
	public R save(@RequestBody MachineryInfoEntity machineryInfo){
		machineryInfoService.save(machineryInfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("machineryinfo:update")
	public R update(@RequestBody MachineryInfoEntity machineryInfo){
		machineryInfoService.update(machineryInfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("machineryinfo:delete")
	public R delete(@RequestBody Integer[] ids){
		machineryInfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
